<template>
<div class="box flex-center">
  <div class="chart" ref="chart"></div>
</div>
</template>

<script>
import echarts from "echarts";
export default {
  props: {
    chartList: {}
  },
  data() {
    return {
      lineChart: null
    }
  },
  watch: {
    chartList: {
      handler() {
        this.initChart()
      },
      deep: true,
    }
  },
  methods: {
    initChart() {
      this.lineChart = echarts.init(this.$refs.chart);
      let option = {
        title: {},
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985"
            }
          }
        },
        color: ["#00C8F4", "#4680FE"],
        legend: {
          // data: ["飞机MB", "人物MB"],
          data: this.chartList.legend,
          itemHeight: 5,
          itemWidth: 25,
          itemGap: 5,
          textStyle: {
            fontSize: 10,
            color: "#868C96"
          }
        },
        grid: {
          // x: 0,
          // y: 0,
          // x2: 0,
          // y2: 0,
          left: "13%",
          right: "10%",
          bottom: "18%",
          top: "20%"
          // containLabel: true,
        },
        xAxis: [{
          type: "category",
          boundaryGap: false,
          // data: [1, 2, 3, 4, 5, 6, 7],
          data: this.chartList.xAxis,
          axisLabel: {
            show: true,
            textStyle: {
              color: "#878D95",
              fontSize: 10,
              align: "center",
            }
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#868C96",
              width: 1
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: ['#868C96'],
              opacity: 0.3,
              width: 1
            }
          }
        }],
        yAxis: [{
          type: "value",
          axisLabel: {
            textStyle: {
              color: "#878D95",
              fontSize: 10
            }
          },
          axisTick: {
            show: false
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: "#868C96",
              width: 1
            }
          },
          splitLine: {
            show: false
          }
        }],
        // series: [{
        //     name: "飞机MB",
        //     type: "line",
        //     data: [300, 0, 500, 400, 200, 300],
        //     symbolSize: 5,
        //   },
        //   {
        //     name: "人物MB",
        //     type: "line",
        //     data: [200, 500, 400, 600, 500, 300, 400],
        //     symbolSize: 5,
        //   }
        // ]
        series: this.chartList.series,
      };
      this.lineChart.setOption(option);
      window.addEventListener("resize", () => {
        this.lineChart.resize();
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.box {
  width: 100%;

  .chart {
    width: 100%;
    height: 1.52rem;
  }
}
</style>
